import os
import struct
from struct import pack,unpack,calcsize

with open(r'D:\ui\hy\youself\456.txt','r') as f:
    s = ' '
    while s:
        s = f.readline()
        # print(s)


# 一次读 / 写一个数字
def write_num(fname,n):
    with open(fname,'wb') as file:
        bss = pack('h',n)
        file.write(bss)


def read_number(fname):
    with open(fname,'rb') as file:
        bss = file.read(calcsize('h'))
        t = unpack('h',bss)
        return t[0]   # 因为返回的是一个元组，即使元组内只有一个元素，也要通过索引才能获取该值


write_num('silly.dat',125)
print(read_number('silly.dat'))


# 一次读 / 写多个数字



